/*
 PureMVC AS3 / Flex Demo - Slacker 
 Copyright (c) 2008 Clifford Hall <clifford.hall@puremvc.org>
 Your reuse is governed by the Creative Commons Attribution 3.0 License
 */
package mvc.view
{
	import flash.events.Event;
	import mvc.ApplicationFacade;
	import mvc.view.components.MainDisplay;
//	import mvc.view.components.CollDisplay;
	
	import org.tools.att.Att;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

    public class MainDisplayMediator extends Mediator
    {
		public static const NAME:String = 'MainDisplayMediator';

		private	function	onTrace(...args):void{Att.send('onTrace',String(Object(this).constructor),args);}

		public function MainDisplayMediator( viewComponent:Object )
		{
			onTrace('	constructor	'+this+'	'+viewComponent);
			super( NAME, viewComponent );
		}
		override public function onRegister():void
		{
			onTrace('	onRegister');
		    mainDisplay.addEventListener( MainDisplay.SPLASH_CREATED,	onSplashCreated  );
		    mainDisplay.addEventListener( MainDisplay.ABOUT_CREATED,	onAboutCreated  );
		    mainDisplay.addEventListener( MainDisplay.ART_CREATED, 		onArtCreated );
		    mainDisplay.addEventListener( MainDisplay.CONTACT_CREATED,	onContactCreated );
		    mainDisplay.addEventListener( MainDisplay.COLL_CREATED,		onCollectionCreated  );
		}
		override public function listNotificationInterests():Array
		{
			onTrace('	listNotificationInterests');
			return [ApplicationFacade.ABOUT_MODE,
					ApplicationFacade.SPLASH_MODE,
					ApplicationFacade.COLL_MODE,
					ApplicationFacade.ART_MODE,
					ApplicationFacade.CONTACT_MODE]
		}
		override public function handleNotification(note:INotification):void
		{
			onTrace('	handleNotification	');
			onTrace(note);
			onTrace();
			switch (note.getName())
			{
				case ApplicationFacade.SPLASH_MODE:		mainDisplay.currentViewSelector = MainDisplay.SPLASH;	break;
				case ApplicationFacade.COLL_MODE:		mainDisplay.currentViewSelector = MainDisplay.COLL;		break;
				case ApplicationFacade.ABOUT_MODE:		mainDisplay.currentViewSelector = MainDisplay.ABOUT;	break;
				case ApplicationFacade.ART_MODE:		mainDisplay.currentViewSelector = MainDisplay.ART;		break;
				case ApplicationFacade.CONTACT_MODE:	mainDisplay.currentViewSelector = MainDisplay.CONTACT;	break;
			}
		}
		protected function onSplashCreated(	event:Event ):void{checkForMediator( MainDisplay.SPLASH,	mainDisplay.activeView );}
		protected function onAboutCreated(	event:Event ):void{checkForMediator( MainDisplay.ABOUT,		mainDisplay.activeView );}
		protected function onArtCreated(	event:Event ):void{checkForMediator( MainDisplay.ART,		mainDisplay.activeView );}
		protected function onContactCreated(event:Event ):void{checkForMediator( MainDisplay.CONTACT,	mainDisplay.activeView );}
		protected function onCollectionCreated(event:Event):void{checkForMediator( MainDisplay.COLL,	mainDisplay.activeView );}
		protected function checkForMediator(childSelector:Number, child:Object ):void
		{
			onTrace('!	checkForMediator	'+childSelector+'	'+child);
			switch (childSelector)
			{
				case MainDisplay.ART:		if (!facade.hasMediator( ArtViewMediator.NAME ))	facade.registerMediator(new ArtViewMediator( child ));break;
				case MainDisplay.COLL:		if (!facade.hasMediator( CollViewMediator.NAME ))	facade.registerMediator(new CollViewMediator( child ));break;
				case MainDisplay.SPLASH:	if (!facade.hasMediator( DefaultViewMediator.NAME ))facade.registerMediator(new DefaultViewMediator( child ));break;
				case MainDisplay.CONTACT:	if (!facade.hasMediator( DefaultViewMediator.NAME ))facade.registerMediator(new DefaultViewMediator( child ));break;
				case MainDisplay.ABOUT:		if (!facade.hasMediator( DefaultViewMediator.NAME ))facade.registerMediator(new DefaultViewMediator( child ));break;
/*
				case MainDisplay.SPLASH:	if (!facade.hasMediator( DefaultViewMediator.NAME ))facade.registerMediator(new DefaultViewMediator( child ));break;
				case MainDisplay.COLL:		if (!facade.hasMediator( CollViewMediator.NAME ))facade.registerMediator(new CollViewMediator( child ));break;
				case MainDisplay.CONTACT:	if (!facade.hasMediator( ContactViewMediator.NAME ))facade.registerMediator(new ContactViewMediator( child ));break;
				case MainDisplay.ART:		if (!facade.hasMediator( ArtViewMediator.NAME ))	facade.registerMediator(new ArtViewMediator( child ));break;
				case MainDisplay.ABOUT:		if (!facade.hasMediator( AboutViewMediator.NAME ))	facade.registerMediator(new AboutViewMediator( child ));break;
/**/
			}        
		}
		protected function get mainDisplay():MainDisplay{return viewComponent as MainDisplay;}
    }
}